﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace CommonUtils
{
	public class Security
	{
		public static string Encrypt(string originalPassword)
		{
			if (originalPassword == null)
				originalPassword = String.Empty;

			//Declarations
			Byte[] originalBytes;
			Byte[] encodedBytes;
			MD5 md5;

			//Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
			md5 = new MD5CryptoServiceProvider();
			originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
			encodedBytes = md5.ComputeHash(originalBytes);

			//Convert encoded bytes back to a 'readable' string
			return BitConverter.ToString(encodedBytes);
		}
	}
}
